import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:oktoast/oktoast.dart';
import 'package:yurun_smartmerchants/generated/json/base/json_convert_content.dart';
import 'package:yurun_smartmerchants/global.dart';
import 'package:yurun_smartmerchants/models/approach_commit_entity.dart';
import 'package:yurun_smartmerchants/models/approach_save_request_entity.dart';
import 'package:yurun_smartmerchants/models/business_entity.dart';
import 'package:yurun_smartmerchants/models/car_add_entity.dart';
import 'package:yurun_smartmerchants/models/car_query_entity.dart';
import 'package:yurun_smartmerchants/models/pic_entity.dart';
import 'package:yurun_smartmerchants/models/upload_image_response_entity.dart';
import 'package:yurun_smartmerchants/net/ApiInterface.dart';
import 'package:yurun_smartmerchants/net/NetUtil.dart';
import 'package:yurun_smartmerchants/page/notification_webview.dart';
import 'package:yurun_smartmerchants/res/colours.dart';
import 'package:yurun_smartmerchants/utils/DialogUtil.dart';
import 'package:yurun_smartmerchants/utils/app_size.dart';
import 'package:yurun_smartmerchants/utils/base64.dart';
import 'package:yurun_smartmerchants/utils/evenbus_utils.dart';
import 'package:yurun_smartmerchants/utils/loading_utils.dart';
import 'package:image_picker/image_picker.dart';

class Enterprisefiling extends StatefulWidget {
  @override
  _EnterprisefilingState createState() => _EnterprisefilingState();
}

class _EnterprisefilingState extends State<Enterprisefiling> {
  ///经营者姓名
  TextEditingController _operatorNameEditingController =
      TextEditingController();
  ///经营者电话
  TextEditingController _operatorPhoneNumberEditingController =
      TextEditingController();
  ///备案类型 临时商户2 固定商户1
  int recordType = 0;
  ///经营类型
  List<BusinessResponseType> type;
  ///已选择经营类型
  String selectMarketName = '';
  int selectMarketId = 0;

  ///身份证号码
  TextEditingController _carNumbereditingController = TextEditingController();

  final _picker = ImagePicker();
  List<ApproachCommit> items = List();
  int position = 0;

  String consumerId;

  File _image;

  bool isSelectButton = true;

  List<BusinessResponseTypechild> currentchildrenType = new List();

  @override
  void initState() {
    super.initState();
    consumerId = Global.prefs.getString(Global.consumer_id);
    for (int i = 0; i < 1; i++) {
      position = i;
      items.add(ApproachCommit());
    }
    getAccountInformation();
    getBusiNessType();
  }

  @override
  void dispose() {
    super.dispose();
  }

  void uploadImage(String files, String ext, String fileName, int postion) {
    LoadingUtil.showLoading(context, tip: '照片上传中...');
    ApiInterface.uploadPublicImage(files, ext, fileName).then((data) {
      PicEntity picEntity = PicEntity.fromJson(data);
      setState(() {
        items[postion].goodsPicUrl = picEntity.content[0].path;
        items[postion].goodsPicId = picEntity.content[0].id;
      });
      //上传图片成功处理
      showToast("上传照片成功");
    }).catchError((onError) {
      setState(() {});
    }).whenComplete(() => LoadingUtil.hideLoading(context));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('企业备案',
            style: TextStyle(fontSize: 18, color: Colours.app_words)),
        backgroundColor: Colours.title_bg,
        iconTheme: IconThemeData(color: Colours.app_words),
      ),
      body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (BuildContext context, int position) {
            return itemWidget(context, position);
          }),
    );
  }

  Widget itemWidget(BuildContext context, int index) {
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(20)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                margin:
                    EdgeInsets.only(left: AppSize.sp(32), top: AppSize.sp(32)),
                width: AppSize.width(5),
                height: AppSize.height(28),
                color: Colours.color_dd4b39,
              ),
              Container(
                alignment: Alignment(-1, 0),
                margin: EdgeInsets.only(left: AppSize.sp(47)),
                child: Text(
                  '基础信息',
                  style: TextStyle(
                      color: Colours.color_313131, fontSize: AppSize.sp(32)),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(2)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                  alignment: Alignment(-1, 0),
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '经营者名称',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(32)),
                alignment: Alignment.centerRight,
                child: TextField(
                  textAlign: TextAlign.right,
                  controller: _operatorNameEditingController,
                  decoration: InputDecoration(
                    hintText: "请输入经营者姓名",
                    hintStyle: TextStyle(
                      fontSize: ScreenUtil().setSp(28),
                      color: Colours.information_placeholder,
                    ),
                    border: InputBorder.none,
                  ),
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(28),
                  ),
                  inputFormatters: <TextInputFormatter>[
                    LengthLimitingTextInputFormatter(20) //限制长度
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                  alignment: Alignment(-1, 0),
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '经营者电话',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(32)),
                alignment: Alignment.centerRight,
                child: TextField(
                  textAlign: TextAlign.right,
                  controller: _operatorPhoneNumberEditingController,
                  decoration: InputDecoration(
                    hintText: "请输入经营者号码",
                    hintStyle: TextStyle(
                      fontSize: ScreenUtil().setSp(28),
                      color: Colours.information_placeholder,
                    ),
                    border: InputBorder.none,
                  ),
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(28),
                  ),
                  inputFormatters: <TextInputFormatter>[
                    LengthLimitingTextInputFormatter(20) //限制长度
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                  alignment: Alignment(-1, 0),
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '备案类型',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Container(
                margin: EdgeInsets.only(left: AppSize.sp(264)),
                alignment: Alignment.centerLeft,
                child: Positioned(
                  top: 12,
                  left: 20,
                  height: 21,
                  child: Row(
                    children: <Widget>[
                      Radio(
                        value: 0,
                        activeColor: Colors.red,
                        onChanged: (value) {
                          setState(() {
                            if (this.recordType != value) {
                              selectMarketName = '';
                              selectMarketId = 0;
                            }
                            this.recordType = value;
                          });
                        },
                        groupValue: this.recordType,
                      ),
                      Text(
                        "临时商户",
                        style: TextStyle(
                          color:
                              this.recordType == 0 ? Colors.red : Colors.black,
                        ),
                      ),
                      SizedBox(
                        width: 20,
                      ),
                      Radio(
                        value: 1,
                        activeColor: Colors.red,
                        onChanged: (value) {
                          setState(() {
                            if (this.recordType != value) {
                              selectMarketName = '';
                              selectMarketId = 0;
                            }
                            this.recordType = value;
                          });
                        },
                        groupValue: this.recordType,
                      ),
                      Text(
                        "固定商户",
                        style: TextStyle(
                          color:
                              this.recordType == 1 ? Colors.red : Colors.black,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                  alignment: Alignment(-1, 0),
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '经营类型',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(32)),
                alignment: Alignment.centerRight,
                child: DropdownButton(
                  items: getListData(),
                  onChanged: _handleMarketType,
                  hint: new Text(
                      selectMarketName.length == 0 ? '市场商户' : selectMarketName),
                  style: new TextStyle(color: Colors.red),
                  isDense: true,
                  iconSize: 25,
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: AppSize.sp(20)),
          width: double.infinity,
          height: AppSize.sp(98),
          color: Colours.white,
          alignment: Alignment.center,
          child: Stack(
            children: <Widget>[
              Container(
                margin:
                    EdgeInsets.only(left: AppSize.sp(32), top: AppSize.sp(32)),
                width: AppSize.width(5),
                height: AppSize.height(28),
                color: Colours.color_dd4b39,
              ),
              Container(
                alignment: Alignment(-1, 0),
                margin: EdgeInsets.only(left: AppSize.sp(47)),
                child: Text(
                  '认证信息',
                  style: TextStyle(
                      color: Colours.color_313131, fontSize: AppSize.sp(32)),
                ),
              ),
            ],
          ),
        ),
        Container(
          width: double.infinity,
          height: AppSize.sp(98),
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          color: Colours.white,
          alignment: Alignment.center,
          child: Row(
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '经营者性质',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Spacer(),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(33)),
                alignment: Alignment.centerLeft,
                child: Positioned(
                  top: 12,
                  left: 20,
                  height: 21,
                  child: Row(
                    children: <Widget>[
                      Radio(
                        value: 0,
                        activeColor: Colors.red,
                        onChanged: (value) {
                          setState(() {
                            if (this.recordType != value) {
                              selectMarketName = '';
                              selectMarketId = 0;
                            }
                            this.recordType = value;
                          });
                        },
                        groupValue: this.recordType,
                      ),
                      Text(
                        "个体户",
                        style: TextStyle(
                          color:
                              this.recordType == 0 ? Colors.red : Colors.black,
                        ),
                      ),
                      Radio(
                        value: 1,
                        activeColor: Colors.red,
                        onChanged: (value) {
                          setState(() {
                            if (this.recordType != value) {
                              selectMarketName = '';
                              selectMarketId = 0;
                            }
                            this.recordType = value;
                          });
                        },
                        groupValue: this.recordType,
                      ),
                      Text(
                        "企业法人",
                        style: TextStyle(
                          color:
                              this.recordType == 1 ? Colors.red : Colors.black,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          width: double.infinity,
          height: AppSize.sp(98),
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          color: Colours.white,
          alignment: Alignment.center,
          child: Row(
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '身份证号码',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                      children: <TextSpan>[
                        TextSpan(
                            text: ' *',
                            style: TextStyle(
                                color: Colours.app_main,
                                fontSize: AppSize.sp(32))),
                      ],
                    ),
                  )),
              Spacer(),
              GestureDetector(
                  onTap: () {},
                  child: Container(
                      margin: EdgeInsets.only(right: AppSize.sp(32)),
                      child: Text(
                        items[index].city == null
                            ? "请输入身份证号码"
                            : items[index].city,
                        style: items[index].city == null
                            ? TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_abacb5)
                            : TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_313131),
                      ))),
            ],
          ),
        ),
        Container(
          width: double.infinity,
          height: AppSize.sp(98),
          margin: EdgeInsets.only(top: AppSize.sp(20)),
          color: Colours.white,
          alignment: Alignment.center,
          child: Row(
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '证件类型',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                    ),
                  )),
              Spacer(),
              GestureDetector(
                  onTap: () {},
                  child: Container(
                      margin: EdgeInsets.only(right: AppSize.sp(12)),
                      child: Text(
                        items[index].city == null ? "卫生许可证" : items[index].city,
                        style: items[index].city == null
                            ? TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_abacb5)
                            : TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_313131),
                      ))),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(32)),
                child: Image.asset(
                  'images/approach_more.png',
                  width: AppSize.width(16),
                  height: AppSize.height(26),
                ),
              )
            ],
          ),
        ),
        Container(
          width: double.infinity,
          height: AppSize.sp(98),
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          color: Colours.white,
          alignment: Alignment.center,
          child: Row(
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '证件编号',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                    ),
                  )),
              Spacer(),
              GestureDetector(
                  onTap: () {},
                  child: Container(
                      margin: EdgeInsets.only(right: AppSize.sp(32)),
                      child: Text(
                        items[index].city == null
                            ? "输入证件编号"
                            : items[index].city,
                        style: items[index].city == null
                            ? TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_abacb5)
                            : TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_313131),
                      ))),
            ],
          ),
        ),
        Container(
          width: double.infinity,
          height: AppSize.sp(98),
          margin: EdgeInsets.only(top: AppSize.sp(1)),
          color: Colours.white,
          alignment: Alignment.center,
          child: Row(
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(left: AppSize.sp(32)),
                  child: RichText(
                    text: TextSpan(
                      text: '证件有效期',
                      style: TextStyle(
                          color: Colours.color_313131,
                          fontSize: AppSize.sp(32)),
                    ),
                  )),
              Spacer(),
              GestureDetector(
                  onTap: () {},
                  child: Container(
                      margin: EdgeInsets.only(right: AppSize.sp(12)),
                      child: Text(
                        items[index].city == null ? "选择有效期" : items[index].city,
                        style: items[index].city == null
                            ? TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_abacb5)
                            : TextStyle(
                                fontSize: AppSize.sp(32),
                                color: Colours.color_313131),
                      ))),
              Container(
                margin: EdgeInsets.only(right: AppSize.sp(32)),
                child: Image.asset(
                  'images/approach_more.png',
                  width: AppSize.width(16),
                  height: AppSize.height(26),
                ),
              )
            ],
          ),
        ),
        Container(
          height: 180,
          color: Colours.white,
          child: Stack(
            children: <Widget>[
              Positioned(
                left: 15,
                top: 11,
                width: 100,
                height: 25,
                child: Row(
                  children: <Widget>[
                    Text(
                      '证件照片',
                      style: TextStyle(
                        fontSize: 18,
                        color: Colors.black,
                      ),
                    ),
                  ],
                ),
              ),
              Positioned(
                left: 15,
                right: 15,
                top: 22,
                height: 165,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Expanded(
                        flex: 1,
                        child: GestureDetector(
                          onTap: () {
                            showModalBottomSheet(
                                context: context,
                                builder: (BuildContext context) {
                                  return _showNomalWid(context);
                                });
                          },
                          child: Container(
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                getImage(),
                              ],
                            ),
                          ),
                        )),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: AppSize.height(180),
          decoration: UnderlineTabIndicator(
              borderSide: BorderSide(width: 0.5, color: Colours.mine_bg),
              insets: EdgeInsets.zero),
          child: Stack(
            alignment: AlignmentDirectional.bottomCenter,
            children: <Widget>[
              Positioned(
                left: 20,
                right: 20,
                top: 10,
                height: 25,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          this.isSelectButton = !this.isSelectButton;
                        });
                      },
                      child: Image.asset(
                        isSelectButton
                            ? 'images/mine_selectimage.png'
                            : 'images/mine_unselect.png',
                        fit: BoxFit.fill,
                        width: AppSize.height(35),
                        height: AppSize.width(35),
                      ),
                    ),
                    Text(
                      '已阅读告知书并同意',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 16.0,
                      ),
                    ),
                    FlatButton(
                      onPressed: () {
                        Navigator.of(context).push(new MaterialPageRoute(
                          builder: (BuildContext context) => WebViewBrowser(
                            url: 'http://www.epfresh.com',
                            title: '告知书',
                          ),
                        ));
                      },
                      child: Text(
                        '《告知书》',
                        style: TextStyle(
                          color: Colors.red,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Positioned(
                left: 20,
                right: 20,
                top: 40,
                height: 44,
                child: RaisedButton(
                  child: Text(
                    '提 交',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                  color: Colors.red,
                  textColor: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10),
                  ),
                  onPressed: submit,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  //选择照片
  Widget _showNomalWid(BuildContext context) {
    return new Container(
        height: AppSize.height(200),
        child: Column(
          children: <Widget>[
            GestureDetector(
                onTap: () {
                  getPic();
                },
                child: Container(
                  child: Text("拍照"),
                  height: AppSize.height(98),
                  width: double.infinity,
                  color: Colours.white,
                  alignment: Alignment.center,
                )),
            Container(
              height: AppSize.height(1),
              width: double.infinity,
              color: Colours.color_dcdcdc,
            ),
            GestureDetector(
                onTap: () {
                  getLocalPic();
                },
                child: Container(
                  child: Text("相册"),
                  height: AppSize.height(98),
                  width: double.infinity,
                  color: Colours.white,
                  alignment: Alignment.center,
                ))
          ],
        ));
  }

  Image getImage() {
    return _image != null
        ? Image.file(
            _image,
            width: AppSize.width(308),
            height: AppSize.height(168),
            fit: BoxFit.cover,
          )
        : Image.asset(
            'images/mine_frontIDcard.png',
            width: AppSize.width(308),
            height: AppSize.height(168),
            fit: BoxFit.cover,
          );
  }

  Future getPic() async {
    PickedFile image = await _picker.getImage(source: ImageSource.camera);
    if (image != null) {
      setState(() {
        _image = File(image.path);
      });
    }
    Navigator.of(context).pop();
    String fileName = image.path
        .substring(image.path.lastIndexOf('/') + 1, image.path.length)
        .toString();
    String ext = image.path
        .substring(image.path.lastIndexOf('.') + 1, image.path.length)
        .toString();
    Base64Tool.imageBase64(image.path).then((base64Str) {
      ApiInterface.uploadPublicImage(base64Str, ext, fileName).then((data) {
        //上传图片成功处理
      });
    });
  }

  Future getLocalPic() async {
    PickedFile image = await _picker.getImage(source: ImageSource.gallery);
    Navigator.of(context).pop();
    if (image != null) {
      setState(() {
        _image = File(image.path);
      });
    }
    String fileName = image.path
        .substring(image.path.lastIndexOf('/') + 1, image.path.length)
        .toString();
    String ext = image.path
        .substring(image.path.lastIndexOf('.') + 1, image.path.length)
        .toString();
    Base64Tool.imageBase64(image.path).then((base64Str) {
      LoadingUtil.showLoading(context, tip: '加载中...');
      ApiInterface.uploadPublicImage(base64Str, ext, fileName).then((data) {
        //上传图片成功处理
      }).catchError((onError) {
        if (onError is LogicError) {
          setState(() {
            //上传失败进行清除
            _image = null;
          });
        }
      }).whenComplete(() => LoadingUtil.hideLoading(context));
    });
  }

  List<DropdownMenuItem> getListData() {
    List<DropdownMenuItem> item = new List();
    if (this.type != null && this.type.length > 1) {
      this.currentchildrenType = this.type[this.recordType].children;
      for (var i = 0; i < this.currentchildrenType.length; i++) {
        DropdownMenuItem dropdownMenuItem = new DropdownMenuItem(
          child: new Text(this.currentchildrenType[i].name),
          value: this.currentchildrenType[i].id,
        );
        item.add(dropdownMenuItem);
      }
    }
    return item;
  }

  void _handleMarketType(item) {
    setState(() {
      for (var i = 0; i < this.currentchildrenType.length; i++) {
        if (this.currentchildrenType[i].id == item) {
          selectMarketName = this.currentchildrenType[i].name;
          selectMarketId = this.currentchildrenType[i].id;
          break;
        }
      }
    });
  }

  void getAccountInformation() async {
    String phone = Global.prefs.getString(Global.phone);
    if(phone.length > 0) {

    }
  }

  void getBusiNessType() {
    ApiInterface.getBusinessType().then((data) {
      BusinessResponse businessResponse =
          JsonConvert.fromJsonAsT<BusinessResponse>(data);
      setState(() {
        this.type = businessResponse.type;
      });
    });
  }

  void submit() {
    //输入验证判断
    if (_operatorNameEditingController.text.length <= 0) {
      showToast('请输入正确的经营者姓名');
      return;
    }

    //经营者电话验证
    if(_operatorPhoneNumberEditingController.text.length <= 0){
      showToast('请输入正确的经营者电话');
      return;
    }


    if (selectMarketId == 0) {
      showToast('请选择经营类型');
      return;
    }

//    bool isAvailable = isCardId(_carNumbereditingController.text);
//    if (!isAvailable && _carNumbereditingController.text.length > 0) {
//      showToast('请输入正确的身份证号码');
//      return;
//    }

    if (!this.isSelectButton) {
      showToast("请勾选并同意告知书");
      return;
    }

    Map<String, dynamic> certification = new Map();
    certification['type'] = 1;
    certification['idCardNo'] = '421083199909092929';

    Map<String, dynamic> parameter = new Map();
    parameter['marketId'] = 1;
    parameter['openId'] = 'oJL0h5XwGg6Zkwo9yGZ3_i6tOzic';
    parameter['name'] = _operatorNameEditingController.text;
    parameter['type'] = 1;
    parameter['businessTypeId'] = 17;
    parameter['remark'] = '11';

//    if (_carNumbereditingController.text.length > 0) {
//      parameter['idCardNo'] = _carNumbereditingController.text;
//    }
//    if(cardentity != null && cardentity.content[0].path.length > 0){//正面照片
//      parameter['fileIdi'] = cardentity.content[0].id;
//      parameter['filePathi'] = cardentity.content[0].path;
//    }
//    if(backcardentity != null && backcardentity.content[0].path.length > 0){//反面照片
//      parameter['fileIdii'] = backcardentity.content[0].id;
//      parameter['filePathii'] = backcardentity.content[0].path;
//    }

    LoadingUtil.showLoading(context, tip: '正在保存，请稍后');
    ApiInterface.personInformationSave(parameter).then((data) {
      LoadingUtil.hideLoading(context);
      Navigator.pop(context);
    }).catchError((error) {
      LoadingUtil.hideLoading(context);
      if (error is LogicError) {
      }
    });
  }

}
